#include "battery.h"
#include "adc.h"

#include "debug.h"

// 20k,10k电阻，如果电阻更换，重新更改该参数
#define VOL_COFF 3
#define BAT_LOW_VOL 3.0f //3.25
#define TIMEOUT_VAL (10u)
#define ADC1_ACCURACY (1ul<<(12u)) 
#define ADC_VREF (3.288f)
static float batVol;							
//static uint16_t m_au16AdcValue[ADC1_CH_COUNT];	
												
void updateBat(void)							
{	
    uint16_t batAdc = 0;
    getChannelValue(9, &batAdc);
	
    batVol = VOL_COFF * (batAdc* ADC_VREF) / (float)ADC1_ACCURACY ; 

    // 电压低通 
    static float batVolLpf;
    batVolLpf += (batVol - batVolLpf) * 0.3f;
}

float getBatVol(void)
{
    return batVol;
}
